import { http } from "@/utils/http";

export type PaymentConfig = {
  id: number;
  name: string;
  app_id: string;
  mch_id: string;
  api_key: string;
  cert_path?: string;
  key_path?: string;
  notify_url?: string;
  status: number;
  created_at: string;
  updated_at: string;
};

export type PaymentConfigResponse = {
  success: boolean;
  code: number;
  message: string;
  data: PaymentConfig;
};

export type PaymentConfigListResponse = {
  success: boolean;
  code: number;
  message: string;
  data: PaymentConfig[];
};

/** 创建支付配置 */
export const createPaymentConfig = (data: Partial<PaymentConfig>) => {
  return http.request<PaymentConfigResponse>("post", "/payment/config", { data });
};

/** 获取支付配置列表 */
export const getPaymentConfigs = () => {
  return http.request<PaymentConfigListResponse>("get", "/payment/config");
};

/** 获取支付配置详情 */
export const getPaymentConfigById = (id: number) => {
  return http.request<PaymentConfigResponse>("get", `/payment/config/${id}`);
};

/** 更新支付配置 */
export const updatePaymentConfig = (id: number, data: Partial<PaymentConfig>) => {
  return http.request<PaymentConfigResponse>("put", `/payment/config/${id}`, { data });
};

/** 删除支付配置 */
export const deletePaymentConfig = (id: number) => {
  return http.request("delete", `/payment/config/${id}`);
};